<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8" />
    <title>删除设备数据</title>
    <script th:src="@{/js/jquery.js}"></script>

</head>
<body>

<form name="billInfo">
	<table width="100%">
		<tr>
    		<td align="center"><h1>删除设备数据</h1></td>
    	</tr>
    </table>
    <table align="center">
    	<tr>
        	<td>设备ID:</td>
            <td>
            	<input id="deviceId" type="text" name="deviceId" style="width: 220px" />
            </td>
            <td>&emsp;&emsp;&emsp;&emsp;</td>
            <td>DeviceNo:</td>
            <td>
            	<input id="deviceNo" type="text" name="deviceNo" style="width: 220px" />
            </td>
            <td>&emsp;&emsp;&emsp;&emsp;</td>
            <td>验证码:</td>
            <td>
            	<div class="col-xs-6 pull_left">
        			<div class="form-group">
            			<input class="form-control" type="tel" id="verify_input" placeholder="请输入验证码" maxlength="4">
            	 	</div>
   		 		</div>
            </td>
            <td>
            	<div class="col-xs-6 pull_left">
            		<a href="javascript:void(0);" title="点击更换验证码">
            			<img id="imgVerify" src="getVerify" alt="更换验证码" height="36" width="170" onclick="getVerify(this);">
            		</a>
    			</div>
            </td>
		</tr>
    </table>
	<table>
    	<tr>
        	<td>&nbsp;</td>
		</tr>
    </table>
    <table align="center">
        <tr>
        	<td>
                <input type="button" value="删除" onclick="deleteDevice()" />
            </td>
		</tr>
    </table>

</form>
</body>


<script type="text/javascript">
	function getVerify() {
		$("#imgVerify").attr("src", 'getVerify?' + Math.random());//jquery方式
	}
	
    function deleteDevice(){
        var deviceId = billInfo.deviceId.value;
        var deviceNo = billInfo.deviceNo.value;
        var secret = $("#verify_input").val();
        if (confirm('您将要删除ID为：'+deviceId+"，编号为："+deviceNo+"的设备数据，请再次确认是否继续？")){
            if (confirm('此操作不可逆，执行后将无法恢复，误删请跑路！')){
				$.ajax({
					type : "POST",
					url : "/deleteDevice",
					data : JSON.stringify({
						"deviceId": deviceId,
						"deviceNo": deviceNo,
						"secret": secret
						}),
					contentType : "application/json",
					success : function(result) {
						if (result.errcode == 200) {
							alert(result.errmsg);
						} else {
							alert("系统异常，联系管理员！");
						}
						getVerify();
					}
				});
            }
        }
    }
</script>
</html>